package com.jzsk.variable.center.domain.vo;

import com.jzsk.variable.center.domain.enums.StatusCodeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 返回对象
 *
 * @author wangjie
 * @date 2021/5/7 13:53
 */
@Data
public class ResponseVO<T> implements Serializable {

    private static final long serialVersionUID = -5634676202510446697L;

    @ApiModelProperty(value = "响应代码")
    private Integer code;

    @ApiModelProperty(value = "响应描述")
    private String message;

    @ApiModelProperty(value = "响应数据")
    private T data;

    public static <T> ResponseVO<T> success() {
        return success(null);
    }

    public static <T> ResponseVO<T> success(T data) {
        ResponseVO<T> responseVO = new ResponseVO<T>();
        responseVO.setCode(StatusCodeEnum.请求成功.getCode());
        responseVO.setMessage(StatusCodeEnum.请求成功.getMessage());
        responseVO.setData(data);
        return responseVO;
    }

    public static <T> ResponseVO<T> error(StatusCodeEnum statusCode) {
        return error(statusCode.getCode(), statusCode.getMessage());
    }

    public static <T> ResponseVO<T> error(StatusCodeEnum statusCode, T data) {
        return error(statusCode.getCode(), statusCode.getMessage(), data);
    }

    public static <T> ResponseVO<T> error(Integer code, String message) {
        return error(code, message, null);
    }

    public static <T> ResponseVO<T> error(Integer code, String message, T data) {
        ResponseVO<T> responseVO = new ResponseVO<T>();
        responseVO.setCode(code);
        responseVO.setMessage(message);
        responseVO.setData(data);
        return responseVO;
    }

}
